using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Chat : System.Web.UI.UserControl
{
	protected string jsSendClientClick {
		get {
			return string.Format(@"
try{{
$get('{0}').focus();
}}catch(e){{}};
",				this.txtMessage.ClientID);
		}
	}
	
	const string VS_CHAT_ID = "chatId";
	#region Properties
	public Guid? ChatID {
		get {
			return (Guid?)this.ViewState[VS_CHAT_ID];
		}
		set {
			this.ViewState[VS_CHAT_ID] = value;
			this.DataBind();
		}
	}

	protected Guid chatId {
		get {
			return this.ChatID.HasValue ? this.ChatID.Value : Guid.Empty;
		}
	}
	#endregion Properties

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.IsPostBack) {
			
			this.DataBind();
		}
	}
	
	protected void UpdatePanel1_Load(object sender, EventArgs e)
	{
		this.lblMessages.DataBind();
	}
	protected void btnSend_Click1(object sender, EventArgs e)
	{
		(new ChatService()).WriteMessage(this.txtMessage.Text, this.chatId);
		this.txtMessage.Text = string.Empty;
	}
	protected void odsUser_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
	{
		e.InputParameters["chatId"] = this.chatId;
	}
	protected void upUsers_Load(object sender, EventArgs e)
	{
		this.DataList1.DataBind();
	}
	protected void btnClear_Click(object sender, EventArgs e)
	{
		(new ChatService()).Delete(this.chatId);
	}
}
